package com.yanqu.road.server.cmd.manor.fishpond;

import com.yanqu.road.pb.manor.FishPondProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.manor.FishPondMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/10/20 15:22
 */
@Cmd(code = GameProtocol.S_FISH_POND_VISIT_OTHER, desc = "鱼塘拜访其他玩家")
public class FishPondVisitOtherCmd extends AbstractCommand {
    private long serverId;
    private long userId;
    private FishPondProto.VisitOtherFishPondReqMsg msg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = FishPondProto.VisitOtherFishPondReqMsg.parseFrom(packet.getBytes());
        serverId = msg.getServerId();
        userId = msg.getPlayerId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (serverId == GameServer.getInstance().getServerId()) {
            FishPondProto.VisitOtherFishPondRespMsg.Builder respMsg;
            //本服拜访
            respMsg = FishPondMgr.getVisitMsg(userId);
            player.sendPacket(ClientProtocol.U_FISH_POND_VISIT_OTHER, respMsg);
        } else {
            //跨服
            player.sendPacket(CrossProtocol.C_CROSS_VISIT_PLAYER_FISH_POND, msg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
